package cn.shop.ylp.controll;

import cn.shop.ylp.ProductMapper;
import cn.shop.ylp.ProductType;
import cn.shop.ylp.ProductTypeMapper;
import cn.shop.ylp.error.CommonReturnType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author yulianpeng
 * @email network_u@163.com
 * Date 2020/9/11
 */
@Controller
@RequestMapping("/producttype")
@CrossOrigin(allowCredentials = "true",allowedHeaders = "*")
public class ProductTypeC extends BaseController{
    @Autowired
    private ProductTypeMapper productTypeMapper;
    @RequestMapping(value = "/productnorm",method = {RequestMethod.GET})
    @ResponseBody
    public CommonReturnType getPNorm(@RequestParam(name = "goodsid") Integer id){
        ArrayList<ProductType> productTypes = productTypeMapper.getProductTypes(id);
        return CommonReturnType.create(productTypes);
    }

    /**
     * 根据规格序列获得规格
     * @param
     * @return
     */
    @RequestMapping(value = "/norms",method = {RequestMethod.POST})
    @ResponseBody
    public CommonReturnType getPNorms(@RequestParam(name = "normsequence") String sequence){
        String[] ids=sequence.split("_");
        ArrayList<ProductType> productTypes = new ArrayList<ProductType>();
        for (int i = 0; i < ids.length; i++) {
            ProductType productType = productTypeMapper
                    .selectByPrimaryKey(Integer.parseInt(ids[i]));
            productTypes.add(productType);
        }
        return CommonReturnType.create(productTypes);
    }

}
